package com.collins.thread.practices.printOddNumber;

public class CountNumber implements Runnable {

    @Override
    public void run() {
        while (true) {
            synchronized (NumberBook.lock) {
                if (NumberBook.num > 99) {
                    break;
                }
                try {
                    Thread.sleep(100);
                    Thread.yield();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                NumberBook.num++;
                if (NumberBook.num % 2 == 1) {
                    System.out.println(Thread.currentThread().getName() + " print odd number:" + NumberBook.num);
                }
            }
        }
    }
}
